import os
import utils
import shutil
from tqdm import tqdm


SrcDir = r"I:\Temp\Temp2"
DstDir = r"I:\Temp\Temp3"
SrcImgShape = (424, 320)
DsrImgShape = (320, 320)
MinSize = (15, 15)


MinW = SrcImgShape[0] / DsrImgShape[0] * MinSize[0]
MinH = SrcImgShape[1] / DsrImgShape[1] * MinSize[1]

for root, dirs, files in os.walk(SrcDir):
    for file in tqdm(files):
        if file[-1] == 'l':
            Infos = utils.ReadXml(root + "\\" + file)
            Key = True
            for Info in Infos:
                if Info[2] - Info[0] < MinW or Info[3] - Info[1] < MinH:
                    Key = False
                    break
            if Key:
                shutil.copy(root + "\\" + file, root.replace(SrcDir, DstDir) + "\\" + file)
                shutil.copy(root + "\\" + file[:-3] + "jpg", root.replace(SrcDir, DstDir) + "\\" + file[:-3] + "jpg")
